<template>
  <el-card class="admin-enterprise-list-card">
    <h2>企业列表</h2>
    <el-table :data="enterprises" stripe border v-loading="loading">
      <el-table-column prop="id" label="ID" min-width="80" />
      <el-table-column prop="enterpriseName" label="企业名称" min-width="120" />
      <el-table-column prop="industry" label="所属行业" min-width="100" />
      <el-table-column prop="scale" label="企业规模" min-width="100" />
      <el-table-column prop="contact" label="联系方式" min-width="120" />
    </el-table>
    <div class="pagination-bar">
      <el-pagination
          background
          layout="prev, pager, next, jumper"
          :total="total"
          :page-size="pageSize"
          :current-page="page"
          @current-change="onPageChange"
      />
    </div>
  </el-card>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { getAllEnterprises } from '@/api/admin'
const enterprises = ref([])
const total = ref(0)
const page = ref(1)
const pageSize = 10
const loading = ref(false)
const allEnterprises = ref([])
const fetchList = async () => {
  loading.value = true
  try {
    const res = await getAllEnterprises({})
    const data = res.data || res
    allEnterprises.value = (data.list || []).map(item => ({
      ...item,
      enterpriseName: item.enterpriseName || item.enterprise_name || ''
    }))
    total.value = allEnterprises.value.length
    const start = (page.value - 1) * pageSize
    const end = start + pageSize
    enterprises.value = allEnterprises.value.slice(start, end)
  } catch (e) {}
  loading.value = false
}
const onPageChange = p => {
  page.value = p
  const start = (page.value - 1) * pageSize
  const end = start + pageSize
  enterprises.value = allEnterprises.value.slice(start, end)
}
onMounted(fetchList)
</script>
<style scoped>
.admin-enterprise-list-card {
  max-width: 1100px;
  margin: 40px auto;
  padding: 30px 20px;
}
.pagination-bar {
  text-align: right;
  margin-top: 10px;
}
</style> 